package cn.fws.meap.user.web;

import java.util.List;

import cn.fws.framework.utils.StringUtils;
import cn.fws.meap.user.vo.UserDetailsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.fws.meap.user.entity.Concern;
import cn.fws.meap.user.service.IConcernService;
import cn.fws.framework.web.contoller.BaseController;
import cn.fws.framework.web.page.PagingResult;
import cn.fws.framework.web.contoller.JsonResponse;

/**
 * 关注用户 信息操作处理
 * 
 * @author chenkh
 * @date 2019-03-07
 */
@RestController
@RequestMapping("/meap/concern")
@Api(tags = "关注用户 信息操作处理")
public class ConcernController extends BaseController{

	@Autowired
	private IConcernService concernService;

	/**
	 * 获取用户的所用粉丝
	 * @param clickOpenid 点击用户详情的id
	 * @param selfOpenid 当前用户id
	 * @return
	 */
	@ApiOperation(value = "获取用户的粉丝")
	@PostMapping("/getFans")
	public PagingResult<UserDetailsVo> getFans(String clickOpenid,String selfOpenid){
		startPage();
		List<UserDetailsVo> userDetailsVo=concernService.getFansList(clickOpenid,selfOpenid);
		return getPagingResult(userDetailsVo);
	}

	/**
	 * 获取所用用户的关注
	 * @param clickOpenid 点击用户详情的id
	 * @param selfOpenid 当前用户id
	 * @return
	 */
	@ApiOperation(value = "获取用户的关注")
	@PostMapping("/getConcern")
	public PagingResult<UserDetailsVo> getConcern(String clickOpenid,String selfOpenid){
		startPage();
		List<UserDetailsVo> userDetailsVo = concernService.getConcernList(clickOpenid,selfOpenid);
		return getPagingResult(userDetailsVo);
	}
	
	/**
	 * 查询关注用户列表
	 */
	//@RequiresPermissions("meap:concern:list")
	@ApiOperation(value = "查询关注用户列表")
	@PostMapping("/list")
	public PagingResult<Concern> list(Concern concern){
		startPage();
        List<Concern> list = concernService.selectList(concern);

		return getPagingResult(list);
	}
	
	/**
	 * 新增保存关注用户
	 */
	//@RequiresPermissions("meap:concern:add")
	@ApiOperation(value = "新增保存关注用户")
	@ApiImplicitParam(name = "concern", value = "新增保存关注用户",dataType = "Concern")
	@PostMapping("/add")
	public JsonResponse addSave(String selfOpenid,String itOpenid)	{
		//当前用户有没有关注过要点击的用户
		Concern concernStatus = concernService.selectConcernStatus(selfOpenid,itOpenid);

		if(StringUtils.isNull(concernStatus)){

			return JsonResponse.success("添加关注",concernService.insert(selfOpenid, itOpenid));

		}else {

			return JsonResponse.success("删除关注",concernService.deleteByOpenId(selfOpenid,itOpenid));

		}
	}

	/**
	 * 修改保存关注用户
	 */
	//@RequiresPermissions("meap:concern:edit")
	@ApiOperation(value = "修改保存关注用户")
	@ApiImplicitParam(name = "concern", value = "修改保存关注用户",dataType = "Concern")
	@PutMapping("/edit")
	public JsonResponse editSave(Concern concern)	{		
		return toAjax(concernService.update(concern));
	}
	
	/**
	 * 删除关注用户
	 */
	//@RequiresPermissions("meap:concern:remove")
	@ApiOperation(value = "删除关注用户")
	@ApiImplicitParam(name = "ids", value = "根据id删除关注用户",dataType = "String")
	@DeleteMapping( "/remove")
	public JsonResponse remove(String ids)	{		
		return toAjax(concernService.deleteByIds(ids));
	}
	
}
